<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #app {
        width: 600px;
        margin: 10px auto;
      }

      .tb {
        border-collapse: collapse;
        width: 100%;
      }

      .tb th {
        background-color: #0094ff;
        color: white;
      }

      .tb td,
      .tb th {
        padding: 5px;
        border: 1px solid black;
        text-align: center;
      }

      .tb img {
        width: 100px;
        height: 100px;
      }

      .add {
        padding: 5px;
        border: 1px solid black;
        margin-bottom: 10px;
      }
    </style>
  </head>
  <body>
    <div id="app">
        <button :disabled="loading" @click="refresh">refresh</button>
      <table class="tb">
        <thead>
          <tr>
            <th>
              <input type="checkbox" name="" id="" />
            </th>
            <th>产品图片</th>
            <th>编号</th>
            <th>品牌名称</th>
            <th>价格</th>
            <th>数量</th>
            <th>操作</th>
          </tr>
        </thead>

        <tbody>
          <tr v-for="item in products" :key="item.id">
            <td>
              <input type="checkbox" name="" id="" />
            </td>
            <td>
              <img
                :src="item.imgSrc"
                alt=""
              />
            </td>
            <td>{{item.id}}</td>
            <td>{{item.name}}</td>
            <td>{{item.price}}</td>
            <td>
              <button>-</button>
              {{item.count}}
              <button>+</button>
            </td>
            <td>
              <button>删除</button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <script src="../../lib/axios.min.js"></script>
    <script src="../../lib/vue3.js"></script>
    <script>
      Vue.createApp({
        data(){
            return{
                products:[],//存放数据
                loading:false,//是否在请求数据中
            }
        },
        methods:{
            //刷新
            refresh(){

                this.loading = true;

                axios.get("http://localhost:3000/products")
                .then((response)=>{
                    console.log(response.data);

                    //赋值给products
                    this.products = response.data
                }).finally(()=>{
                    this.loading = false
                })
            }
        }
      }).mount("#app");
    </script>
  </body>
</html>